﻿using System;
using System.Collections.Generic;
using StockLib.UserData;
using StockUtil;

namespace StockLib
{
    public class StockBlockGroupCustom : StockBlockGroup
    {
        /// <summary>
        /// "自定义"板块组名称
        /// </summary>
        public const string BLOCK_GROUP_NAME = "板块";

        /// <summary>
        /// "自定义"板块组ID
        /// </summary>
        public const string BLOCK_GROUP_ID = BLOCK_GROUP_NAME + ".";

        /// <summary>
        /// "自选股"板块名称
        /// </summary>
        public const string ZXG_BLOCK_NAME = "自选股";

        /// <summary>
        /// "自选股"板块ID
        /// </summary>
        public const string ZXG_BLOCK_ID = BLOCK_GROUP_ID + ZXG_BLOCK_NAME;

        /// <summary>
        /// 单例实例
        /// </summary>
        private static StockBlockGroupCustom _instance = new StockBlockGroupCustom();

        /// <summary>
        /// 构造函数
        /// </summary>
        private StockBlockGroupCustom()
            : base()
        {
        }

        /// <summary>
        /// 访问单例
        /// </summary>
        /// <returns></returns>
        public static StockBlockGroupCustom Instance
        {
            get
            {
                return _instance;
            }
        }

        /// <summary>
        /// 加载"自定义"板块组数据
        /// </summary>
        public override void Load()
        {
            StockUserData.Instance.LoadBlockData();
        }

        /// <summary>
        /// 保存"自定义"板块组数据
        /// </summary>
        public override void Save()
        {
            StockUserData.Instance.SaveBlockData();
        }

        /// <summary>
        /// 访问"自选股"板块
        /// </summary>
        public StockBlock ZXGBlock
        {
            get
            {
                return GenerateZXGBlock();
            }
        }

        /// <summary>
        /// 生成"自选股"板块
        /// </summary>
        /// <returns></returns>
        public StockBlock GenerateZXGBlock()
        {
            if (!this.ContainsKey(ZXG_BLOCK_ID))
            {
                StockBlock block = new StockBlock();
                block.Name = ZXG_BLOCK_NAME;
                block.ShortName = StringHelper.GetPinYin(block.Name);
                block.GroupName = BLOCK_GROUP_NAME;
                block.StockNumber = 0;
                this.Add(block.BlockId, block);
            }

            return this[ZXG_BLOCK_ID];
        }
    }
}
